home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / modes / c-style.el.z / c-style.el
Encoding:
Text File  |  1998-05-21  |  5.8 KB  |  200 lines

  1. ;; c-style.el --- sets c-style control variables.
  2. ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of XEmacs.
  5.  
  6. ;; XEmacs is free software; you can redistribute it and/or modify it
  7. ;; under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; XEmacs is distributed in the hope that it will be useful, but
  12. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. ;; General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  18. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. ;; Boston, MA 02111-1307, USA.
  20. ;;
  21. ;; LCD Archive Entry:
  22. ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
  23. ;; |sets c-style control variables
  24. ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
  25. ;;
  26. ;;; Synched up with: Not in FSF.
  27.  
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;;;
  30. ;;; There are several ways to call set-c-style described below.
  31. ;;; None of these methods reindent your program - they only affect
  32. ;;; new indentation.
  33. ;;;
  34. ;;; - Just call set-c-style in your c-mode-hook.
  35. ;;;    Without style argument, default-c-style will be used.
  36. ;;;    With style argument, this will set the style for every 
  37. ;;;    c-mode buffer the same.
  38. ;;;
  39. ;;; - Call set-c-style from the Local Variables list.
  40. ;;;    e.g. "eval:(set-c-style 'C++)"
  41. ;;;
  42. ;;; - Call set-c-style interactively.  It prompts for the style name
  43. ;;;    with completion using default-c-style.
  44. ;;;
  45. ;;; For convenience, put one of the following in your .emacs:
  46. ;;;    (autoload 'set-c-style "c-style" nil t)
  47. ;;; or (load "c-style")
  48. ;;; =====================================================
  49.  
  50. (defvar default-c-style 'GNU
  51.   "*The default value of c-style.  Set this in your .emacs.")
  52.  
  53. ;; The following predefined styles are all I know about.
  54. ;; If you learn of another style that has a "big" following, please
  55. ;; send me the parameters.
  56.  
  57. (defvar c-style-alist 
  58.   '((GNU 
  59.      (c-indent-level 2)
  60.      (c-continued-statement-offset 2)
  61.      (c-brace-offset 0)
  62.      (c-argdecl-indent 5)
  63.      (c-label-offset -2))
  64.  
  65.     (BSD
  66.      (c-indent-level 8)
  67.      (c-continued-statement-offset 8)
  68.      (c-brace-offset -8)
  69.      (c-argdecl-indent 8)
  70.      (c-label-offset -8))
  71.  
  72.     (K&R 
  73.      (c-indent-level 5)
  74.      (c-continued-statement-offset 5)
  75.      (c-brace-offset -5)
  76.      (c-argdecl-indent 0)
  77.      (c-label-offset -5))
  78.  
  79.     (BS   ; was C++ 
  80.      (c-indent-level 4)
  81.      (c-continued-statement-offset 4)
  82.      (c-brace-offset -4)
  83.      (c-argdecl-indent 4)
  84.      (c-label-offset -4))
  85.  
  86.     ;; From Lynn Slater
  87.     (LRS
  88.      (c-indent-level 4)
  89.      (c-continued-statement-offset 4)
  90.      (c-brace-offset 0)
  91.      (c-argdecl-indent 4)
  92.      (c-label-offset -2)
  93.      (c-auto-newline nil))
  94.  
  95.     (Plauger
  96.      (c-indent-level 0)
  97.      (c-continued-statement-offset 8)
  98.      (c-continued-brace-offset -8)
  99.      (c-brace-offset 8)
  100.      (c-brace-imaginary-offset 0)
  101.      (c-argdecl-indent 0)
  102.      (c-label-offset -8)
  103.      (c-auto-newline t)
  104.      (c-tab-always-indent t))
  105.  
  106.     ;; From Jozsef A Toth <jtoth+@pitt.edu>
  107.     ;; Is this really the Whitesmith style?
  108.     (Alman                
  109.      (c-argdecl-indent 0)
  110.      (c-brace-imaginary-offset 2)  ;;; ????
  111.      (c-brace-offset 0)
  112.      (c-continued-statement-offset 2)
  113.      (c-indent-level 0)
  114.      (c-label-offset -2)
  115.      (c-auto-newline t)
  116.      (comment-column 40)
  117.      (tab-width 2)
  118.      (fill-column '79))
  119.  
  120.     (Gould
  121.      (c-indent-level 4)
  122.      (c-continued-statement-offset 4)
  123.      (c-brace-offset -4)
  124.      (c-argdecl-indent 8)
  125.      (c-label-offset -2)
  126.      (c-brace-imaginary-offset 0))
  127.      
  128.     ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
  129.     (WRS 
  130.      (c-indent-level 0)
  131.      (c-continued-statement-offset 4)
  132.      (c-brace-offset 0)
  133.      (c-argdecl-indent 4)
  134.      (c-label-offset -2)
  135.      (c-brace-imaginary-offset 4)
  136.      (c-continued-brace-offset -4))
  137.     ))
  138.   
  139. (defvar c-style nil
  140.   "The buffer local c-mode indentation style.")
  141.  
  142. ;; Add style name to mode line.  Assumes minor-mode-alist is not buffer local.
  143. ;; Thanks to Joan Eslinger.
  144.  
  145. (defvar c-style-name nil
  146.   "The style name for a c-mode indentation style.
  147. This is to be set by set-c-style, and used by the mode line.")
  148.  
  149. (or (assq 'c-style-name minor-mode-alist)
  150.     (setq minor-mode-alist
  151.       (purecopy
  152.        (append minor-mode-alist
  153.            ;; use undocumented feature
  154.            '((c-style-name c-style-name))))))
  155.  
  156. (defun set-c-style (&optional style)
  157.   "Set up the c-mode style variables from STYLE if it is given, or
  158. default-c-style otherwise.  It makes the c indentation style variables
  159. buffer local."
  160.  
  161.   (interactive)
  162.  
  163.   (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
  164.     (if (interactive-p)
  165.     (setq style
  166.           (let ((style-string    ; Get style name with completion.
  167.              (completing-read
  168.               (format "Set c-mode indentation style to (default %s): "
  169.                   default-c-style)
  170.               (vconcat c-styles)
  171.               (function (lambda (arg) (memq arg c-styles)))
  172.               )))
  173.         (if (string-equal "" style-string)
  174.             default-c-style
  175.           (intern style-string))
  176.         )))
  177.     
  178.     ;; If style is nil, use default-c-style.
  179.     (setq style (or style default-c-style))
  180.     
  181.     (make-local-variable 'c-style)
  182.     (if (memq style c-styles)
  183.     (setq c-style style)
  184.       (error "Undefined c style: %s" style)
  185.       )
  186.     (message "c-style: %s" c-style)
  187.     
  188.     ;; Set the c-style-name
  189.     (make-local-variable 'c-style-name)
  190.     (setq c-style-name (format " %s" c-style))
  191.  
  192.     ;; Finally, set the indentation style variables making each one local.
  193.     (mapcar (function (lambda (c-style-pair)
  194.             (make-local-variable (car c-style-pair))
  195.             (set (car c-style-pair)
  196.                  (car (cdr c-style-pair)))))
  197.         (cdr (assq c-style c-style-alist)))
  198.     c-style
  199.     ))
  200.